package com.itheima.Test;

//定义一个Student类，属性：姓名、性别、年龄。
public class Student {
    private String name;
    private char sex;
    private int age;

    public Student() {
    }

    public Student(String name, char sex, int age) {
        this.name = name;
        if(sex=='男'||sex=='女'){
            this.sex = sex;
        }else{
            throw new SexException("性别有误");
        }
        if (age>=15 && age<=50){
           this.age = age  ;
        }else{
            throw new AgeException("年龄超出范围");
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        if(sex=='男'||sex=='女'){
            this.sex = sex;
        }else{
            throw new SexException("性别有误");
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age>=15 && age<=50){
            this.age = age  ;
        }else{
            throw new AgeException("年龄超出范围");
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sex=" + sex +
                ", age=" + age +
                '}';
    }
}
